home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / AmigaMail / Aspect / GetAspect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-27  |  2.9 KB  |  114 lines

  1. ;/* getaspect.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 getaspect.c
  3. Blink FROM LIB:c.o,getaspect.o TO getaspect LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5.  
  6. Gets X/Y pixel aspect of a screen's ViewPort
  7. */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <libraries/dos.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/intuitionbase.h>
  14. #include <graphics/displayinfo.h>
  15. #include <graphics/gfxbase.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24.  
  25. #ifdef LATTICE
  26. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  27. int chkabort(void) { return(0); }  /* really */
  28. #endif
  29.  
  30.  
  31. #define MINARGS 1
  32.  
  33. UBYTE *vers = "\0$VER: getaspect 37.1";
  34. UBYTE *Copyright = 
  35.   "getaspect v37.1\nCopyright (c) 1990-1999 Amiga, Inc.  All Rights Reserved";
  36. UBYTE *usage = "Usage: getaspect";
  37.  
  38. void bye(UBYTE *s, int e);
  39. void cleanup(void);
  40.  
  41. struct Library *IntuitionBase;
  42. struct Library *GfxBase;
  43.  
  44. void main(int argc, char **argv)
  45.     {
  46.     struct Screen *first;
  47.     struct ViewPort *vp;
  48.     struct DisplayInfo DI;
  49.     ULONG  modeid;
  50.     UBYTE  xAspect, yAspect;
  51.  
  52.     if(((argc)&&(argc<MINARGS))||(argv[argc-1][0]=='?'))
  53.     {
  54.     printf("%s\n%s\n",Copyright,usage);
  55.     bye("",RETURN_OK);
  56.     }
  57.  
  58.     /* We will check later to see if we can call V36 functions */
  59.     IntuitionBase = OpenLibrary("intuition.library",34);
  60.     GfxBase = OpenLibrary("graphics.library",34);
  61.     if((!IntuitionBase)||(!GfxBase))
  62.     bye("Can't open intuition or graphics library",RETURN_FAIL);
  63.  
  64.     printf("Using front screen's ViewPort for example purposes only:\n");
  65.      
  66.     first = ((struct IntuitionBase *)IntuitionBase)->FirstScreen;
  67.     vp = &first->ViewPort;
  68.  
  69.     xAspect = 0;    /* So we can tell when we've got it */
  70.  
  71.     if(GfxBase->lib_Version >= 36)
  72.     {
  73.         modeid = GetVPModeID(vp);
  74.  
  75.         if(GetDisplayInfoData(NULL, (UBYTE *)&DI, sizeof(struct DisplayInfo),
  76.         DTAG_DISP, modeid))
  77.         {
  78.         printf("Running 2.0,  ViewPort modeid is $%08lx\n",modeid); 
  79.         xAspect = DI.Resolution.x;
  80.         yAspect = DI.Resolution.y;
  81.         printf("Pixel  xAspect=%ld  yAspect=%ld\n",xAspect, yAspect);
  82.         printf("PaletteRange is %ld\n",DI.PaletteRange);
  83.         }
  84.     }
  85.  
  86.     if(!xAspect)  /* pre-2.0 or GetDisplayInfoData failed */
  87.     {
  88.     modeid = vp->Modes;
  89.     printf("Not running 2.0, ViewPort mode is $%04lx\n",modeid); 
  90.         /* default lores pixel ratio */
  91.         xAspect = 44;
  92.         yAspect = ((struct GfxBase *)GfxBase)->DisplayFlags & PAL  ? 44 : 52;
  93.         if(modeid & HIRES)      xAspect = xAspect >> 1;
  94.         if(modeid & LACE)       yAspect = yAspect >> 1;
  95.     printf("Pixel  xAspect=%ld  yAspect=%ld\n",xAspect, yAspect);
  96.         }
  97.  
  98.     bye("",RETURN_OK);
  99.     }
  100.  
  101.  
  102. void bye(UBYTE *s, int e)
  103.     {
  104.     cleanup();
  105.     exit(e);
  106.     }
  107.  
  108. void cleanup()
  109.     {
  110.     if(GfxBase)    CloseLibrary(GfxBase);
  111.     if(IntuitionBase)    CloseLibrary(IntuitionBase);
  112.     }
  113.  
  114.